


var find = {
    clew: '',
    init: function () {
        var that = this
        var i = $("#find")
        i.click(function () {
            clew = $('#clew').val()
            that.clew = clew
            that.ifind(clew)
        })
    },
    ifind: function (clew) {
        var that = this
        var itemclew = {
            clew: clew
        }
        $.ajax({
            url: "/find",
            type: 'POST',
            data: JSON.stringify(itemclew),
            dataType: 'text',
            success: function (res) {
                var reso = JSON.parse(res)
                if (reso['code'] != 0) {
                    alert(reso['desc'])
                }
                parent.interHTML = ''
                that.ShowItems(reso['data'])
            }
        });
    },
    ItemDelete: function (idd) {
        var that = this
        var item = {
            id: idd
        }
        $.ajax({
            url: "/delete",
            type: 'POST',
            data: JSON.stringify(item),
            dataType: 'text',
            success: function (res) {
                var reso = JSON.parse(res)
                alert(reso['desc'])
                parent.interHTML = ''
                that.ifind(that.clew)
            }
        });
    },
    ShowItems: function (items) {
        var parent = $('#items')[0]
        var inhtml = ''
        for (var i in items) {
            var one =
                "<p>" +
                "<div margin='10px 10px'>" +
                "<div style='height:30%;background-color:#fffff4;float:left';width:80%>" +
                "<div>物品名称:" + items[i]['name'] + "</div>" +
                "<img width='100px height='100px' src='" + items[i]['pic'] + "'>" +
                "</img>" +
                "<div>属性:" + items[i]['attr'] + "</div>" +
                "<div>位置:" + items[i]['position'] + "</div>" +
                "</div>" +
                "<div style='float:left;background-color:#F0F0F0;height:50%;width:20%'>" +
                "<div>更新时间:" + items[i]['updateTime'] + "</div>" +
                "<div class='buttom1'>" +
                "<button  onclick='find.ItemDelete(" + items[i]['id'] + ")'>刪除</button>" +
                "</div>" +
                "</div>" +
                "<div style='clear:both'></div>" +
                "</div>" +
                "</br><hr/>" +
                "</p>"
            inhtml += one
        }
        parent.innerHTML = inhtml
        if(items.length==0){
	    parent.innerHTML = "没有找到任何物品"
        }
    }
}
$(document).ready(function () {
    find.init();
});
